package com.his.admin.controller;

import com.his.admin.service.InterfaceService;
import com.his.dao.domain.dto.ListDto;
import com.his.dao.domain.entity.Hospital;
import com.his.dao.domain.entity.MInterface;
import com.his.util.annotation.RequiresLogin;
import com.his.util.annotation.RequiresPermissions;
import com.his.util.result.RestResult;
import com.his.util.result.RestResultBuilder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/interface")
@AllArgsConstructor
@Api(value = "接口模块")
public class InterfaceController {
    private InterfaceService interfaceService;

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/all")
    @ApiOperation(value = "获取接口列表",notes = "获取接口列表")
    public RestResult all(@RequestBody ListDto listDto) {
        return interfaceService.all(listDto);
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/add")
    @ApiOperation(value = "增加接口",notes = "增加接口")
    public RestResult add(@RequestBody MInterface mInterface) {
        if (interfaceService.save(mInterface)) {
            return new RestResultBuilder().success();
        }
        return new RestResultBuilder().fail();
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/update")
    @ApiOperation(value = "更新接口",notes = "更新接口")
    public RestResult update(@RequestBody MInterface mInterface) {
        if (interfaceService.updateById(mInterface)) {
            return new RestResultBuilder().success();
        }
        return new RestResultBuilder().fail();
    }

    @RequiresLogin
    @RequiresPermissions
    @RequestMapping("/delete")
    @ApiOperation(value = "删除接口",notes = "删除接口")
    public RestResult delete(@RequestBody List<Integer> ids) {
        if (interfaceService.removeByIds(ids)) {
            return new RestResultBuilder().success();
        }
        return new RestResultBuilder().fail();
    }
}